package com.minelx.woods.server.config;

import com.minelx.landisk.filesystem.Paths;
import com.minelx.landisk.filesystem.core.Directory;
import com.minelx.landisk.filesystem.core.init.OpenPolicy;
import com.minelx.woods.server.dao.ReviewerMappings;
import com.minelx.woods.server.dao.UserRepository;
import com.minelx.woods.server.entity.Reviews;
import com.minelx.woods.server.entity.Tasks;
import com.minelx.woods.server.entity.Users;
import com.mongodb.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import org.bson.Document;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static com.minelx.landisk.filesystem.core.init.OpenPolicy.useExistingOrCreateANewOne;

@Configuration
public class Config {
	@Bean(destroyMethod = "close")
	MongoClient client() {
	    return new MongoClient("localhost", 27017);
	}

	@Bean
	Directory taskFilesDirectory() {
	    return Paths.root("/E:/woods_downloading_directory", useExistingOrCreateANewOne());
	}

	@Bean
	MongoDatabase database(MongoClient client) {
		return client.getDatabase("woods_db");
	}

	@Bean
	MongoCollection<Document> tasksCollection(MongoDatabase database) {
	    return database.getCollection("tasks");
	}

	@Bean
	MongoCollection<Document> reviewsCollection(MongoDatabase database) {
		return database.getCollection("reviews");
	}

	@Bean
	MongoCollection<Document> reviewerMappingsCollection(MongoDatabase database) {
		return database.getCollection("reviewer_mappings");
	}

	@Bean
	ReviewerMappings reviewerMappings(MongoCollection<Document> reviewerMappingsCollection) {
	    return new ReviewerMappings(reviewerMappingsCollection);
	}

	@Bean
	Tasks tasksInfo(MongoCollection<Document> tasksCollection) {
	    return new Tasks(tasksCollection);
	}

	@Bean
	Reviews reviews(MongoCollection<Document> reviewsCollection) {
	    return new Reviews(reviewsCollection);
	}

	@Bean
	Users users(UserRepository userRepository) {
	    return new Users(userRepository);
	}
}
